package me.algo.dy;

import java.util.Objects;

/**
 * @author guozheng
 * @date 2024/5/9
 */
public class D1 {


    /*
    * 1 2 3 4 5
    * 1 2 3 4 5
    * 1 2 3 4 5
    * 1 2 3 4 5
    * 1 2 3 4 5
    * */
    public static void main(String[] args) {
        var nums = new int[]{2,1};
        System.out.println(jump(new int[]{2,3,1,1,4}));
        System.out.println(jump(new int[]{2,3,0,1,4}));
        System.out.println(jump(new int[]{0}));
        System.out.println(jump(new int[]{2,1}));
        System.out.println(jump(new int[]{2,3,1}));
    }

    /**
     * 45
     * @param nums
     * @return
     */
    public static int jump(int[] nums) {
        if (Objects.isNull(nums) || nums.length == 0) {
            return 0;
        }
        // 最后一个位置
        int pos = nums.length - 1;
        int times = 0;
        while (pos > 0) {
            for (int i = 0; i < pos; i++) {
                if (i + nums[i] >= pos) {
                    pos = i;
                    times++;
                    break;
                }
            }
        }
        return times;
    }
}
